﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H


#include <QLabel>
#include <QComboBox>
#include <QWidget>
#include <QtSerialPort/QSerialPortInfo>
#include <QLineEdit>
#include <QPushButton>
#include <QMessageBox>
#include <QRadioButton>
#include <QButtonGroup>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPlainTextEdit>
#include <QProgressBar>
#include <QFileDialog>
#include <QTimer>
#include <QAbstractNativeEventFilter>
#include <QtMsgHandler>
#include <QSettings>


class MainWindow : public QWidget
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    QLabel    *label_port;
    QComboBox *combo_box_port;
    QLabel    *label_bard;
    QComboBox *combo_box_bard;
    QLabel    *label_check;
    QComboBox *combo_box_check;
    QLabel    *label_date;
    QComboBox *combo_box_date;
    QLabel    *label_stop;
    QComboBox *combo_box_stop;
    QLabel    *label_serial_open;
    QPushButton *btn_serial_open;

    QSerialPort *serial_useing_port;

    QLabel  *recv_label_asc2;
    QPushButton *recv_btn_clean;
    QButtonGroup *gup_btn_check_asc2;
    QRadioButton *ra_btn_check_asc2;
    QRadioButton *ra_btn_check_not_asc2;
    QLabel  *send_label_asc2;
    QPushButton *send_btn_clean;
    QButtonGroup *send_gup_btn_check_asc2;
    QRadioButton *send_ra_btn_check_asc2;
    QRadioButton *send_ra_btn_check_not_asc2;
    QPushButton  *send_btn_date;

    QPlainTextEdit *recv_text_edit;
    QPlainTextEdit *send_text_edit;

    QLabel  *file_send_label;
    QLabel  *file_name_label;
    QLineEdit *file_line_edit;
    QProgressBar *file_send_pross_bar;
    QPushButton *file_select_btn;
    QPushButton *file_send_btn;
    QString file_useing_name;
    QFile *file_sending;
    qint64 file_total_bytes;
    quint16 file_max_send_bytes;
    qint64 file_have_send_bytes;
    bool file_send_over;

    QTimer *file_send_timer;
    QTimer *update_com_port_timer;
    QSettings *file_open_last_path;
    bool  m_file_name_seng_flag;





private:
    void setUI();
    void m_setlabel_style(QLabel *setLable,int x,int y,int w, int h,QFont labelFont,const char* text);
    void m_setcombox_style(QComboBox *box,int x,int y,int w, int h,QList<QString> *items);

    void date_init();
    QList<QString>* get_all_port();
    int serial_open();

private:
    QList<QString> *g_all_ports;
    QList<QString> *g_all_bard;
    QList<QString> *g_all_check;
    QList<QString> *g_all_date;
    QList<QString> *g_all_stop;




private slots:
    void select_bard_change(int index);
    void serial_open_btn_fun();
    void serial_read_fun();
    void btn_clean_recv_date();
    void btn_clean_send_date();
    void btn_send_date();
    void file_select_btn_fun();
    void file_send_btn_fun();
    void file_send_by_timer();
    void update_com_port_fun();



};
#endif // MAINWINDOW_H
